package store.aixx.security.ch4.validation;

import store.aixx.security.ch4.annotating.PasswordMatch;
import store.aixx.security.ch4.domain.dto.UserDTO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Objects;

/**
 * @author yukai
 * @since 2021年12月05日 14:45
 */
public class PasswordMatchValidtor implements ConstraintValidator<PasswordMatch, UserDTO> {
    @Override
    public void initialize(PasswordMatch constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(UserDTO userDTO, ConstraintValidatorContext constraintValidatorContext) {
        return Objects.equals(userDTO.getPassword(), userDTO.getMatchPassword());
    }
}
